#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <vector>
#include "vector.h"
#include "test_vector.h"

namespace test
{
void test_vector_1()
{
    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);
    v.print();

    vector<int> v1(v);
    v1.print();

    vector<int> v2;
    v2 = v1;
    v2.print();

    v.resize(10, 8);
    v.print();
    cout << v.size() << endl;
    v.resize(3);
    v.print();
    cout << v.size() << endl;

    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i] << " ";
    }
    cout << endl;

    cout << "------------------------" << endl;
    v.print();
    v.pop_back();
    v.print();
    v.pop_back();
    v.print();
    v.pop_back();
    v.print();
    // v.pop_back();
    // v.print();

    v.push_back(1);
    v.push_back(2);
    v.push_back(4);
    v.push_back(5);
    v.push_back(6);
    v.push_back(7);
    v.push_back(8);
    v.print();

    v.insert(v.begin(), 0);
    v.insert(v.begin() + 3, 3);
    v.insert(v.end(), 9);
    v.print();


    vector<int>::iterator it = v.begin();
    while (it != v.end())
    {
        if (*it % 2 == 0)
        {
            it = v.erase(it);
        }
        else
        {
            ++it;
        }
    }

    v.print();
}

void test_vector_expand()
{
    vector<int> v;
    size_t      sz    = v.capacity();
    size_t      n     = 1000000;
    size_t      begin = clock();
    v.reserve(n);
    for (int i = 0; i < n; ++i)
    {
        v.push_back(i);
        if (sz != v.capacity())
        {
            sz = v.capacity();
            cout << sz << endl;
        }
    }
    size_t end = clock();
    cout << "count time: " << end - begin << endl;
}

void test_reverse_iterator()
{
    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);

    vector<int>::iterator it = v.begin();
    while (it != v.end())
    {
        cout << *it << " ";
        ++it;
    }
    cout << endl;

    vector<int>::reverse_iterator rit = v.rbegin();
    while (rit != v.rend())
    {
        cout << *rit << " ";
        ++rit;
    }
    cout << endl;
}

}

int main()
{
    // vector<int>::iterator it;
    // cout << typeid(it).name() << endl;
    // test::test_vector_1();

    test::test_reverse_iterator();


    return 0;
}